﻿package app.model 
{
    import flash.events.Event;
    import flash.net.URLLoader;
    import app.model.vo.Config;
    import flash.net.URLRequest;
    import org.puremvc.as3.interfaces.IProxy;
    import org.puremvc.as3.patterns.proxy.Proxy;
    import app.ApplicationFacade;
    /**
    * Author lzyy
    * Email:healdream@gmail.com
    * Blog:http://lab.lzyy.name/blog
    */
    public class DataProxy extends Proxy implements IProxy
    {
        public static const NAME:String = 'DataProxy';
        public function DataProxy() 
        {
            super(NAME, new Object());
            var loader:URLLoader = new URLLoader();
            loader.addEventListener(Event.COMPLETE, _onDataLoaded);
            loader.load(new URLRequest(Config.XML_ADDR));
        }
        
        private function _onDataLoaded(evt:Event)
        {
            var xml:XML = XML(evt.target.data);
            xml.ignoreWhitespace = true;
            var xmlList:XMLList = xml.list;
            data.title = new Array();
            data.intro = new Array();
            data.link = new Array();
            data.imgurl = new Array();
            for (var i = 0; i < xmlList.length(); i++)
            {
                data.title.push(xmlList[i].title.toString());
                data.intro.push(xmlList[i].intro.toString());
                data.link.push(xmlList[i].link.toString());
                data.imgurl.push(xmlList[i].imgurl.toString());
            }
            sendNotification(ApplicationFacade.INIT);
        }
        
    }
    
}